package org.activequant.data.retrieval.dao;

import org.activequant.core.domainmodel.SeriesSpecification;
import org.activequant.core.domainmodel.data.MarketDepthEventSeries;
import org.activequant.dao.IMarketDepthEventDao;
import org.activequant.data.retrieval.IMarketDepthEventSeriesSource;
import org.apache.log4j.Logger;

/**
* MarketDepthEvent series source that fetches data from the database.<br/>
* An IMarketDepthEventSeriesSource implementation. Holds the following associated variables:
* <ul>
* <li>dao(IMarketDepthEventDao)</li>
* </ul>
*/
public class DaoMarketDepthEventSeriesSource implements IMarketDepthEventSeriesSource {

	private final Logger log = Logger.getLogger(getClass());
	/**
	 * private IMarketDepthEventDao dao;
	 */
	private IMarketDepthEventDao dao;
	/**
	 * returns the associated dao(IMarketDepthEventDao)
	 * @return
	 */
	public IMarketDepthEventDao getDao() {
		return dao;
	}
	/**
	 * sets the associated dao(IMarketDepthEventDao) with the given val(IMarketDepthEventDao)
	 * @param val
	 */
	public void setDao(IMarketDepthEventDao val) {
		dao = val;
	}
	/**
	 * returns a MarketDepthEventSeries whose associated seriesSpecification(SeriesSpecification) is set with the given specs(SeriesSpecification).<br/>
	 * Sets its MarketDepthEvent elements by fetching the MarketDepthEvent(s) for the given specs(SeriesSpecification) from the associated dao(IMarketDepthEventDao).
	 */
	public MarketDepthEventSeries fetch(SeriesSpecification specs) throws Exception {
		if(dao == null) {
			throw new IllegalStateException("dao property not set");
		}
		MarketDepthEventSeries series = new MarketDepthEventSeries(specs);
		log.debug("populating series from the data source: " + specs);
		series.setMarketDepthEvents(dao.findBySeriesSpecification(specs));
		return series;
	}
	/**
	 * returns the simple name of this class
	 * @return
	 */
	public String getVendorName() {
		return getClass().getSimpleName();
	}
}
